/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.server.db.tasks;

import java.util.logging.Logger;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import pl.cezary.butler.walili.server.db.tables.ZadPolozenie;
import pl.cezary.butler.walili.server.db.tables.ZadReszta;
import pl.cezary.butler.walili.server.db.tables.ZadaniaId;
import pl.cezary.butler.walili.server.db.utils.JdbcTemplate;
import pl.cezary.butler.walili.server.db.utils.TableDefinitionUtils;

/**
 *
 * @author Przemysław Bałdyga
 */
public class CleanDbTask extends UpdateTask {

    private static final Logger log = Logger.getLogger("ZadanieAktualizacjaBD");

    @Override
    public void execute() {
        final JdbcTemplate tmpl = getJdbcTemplate();

        tmpl.update("DELETE FROM zad_polozenie");
        KeyHolder kh = new GeneratedKeyHolder();
        int id_polozenie = tmpl.insert(ZadPolozenie.class, getIdFactory().generateId());


        tmpl.update("DELETE FROM zad_reszta");
        int id_reszta = tmpl.insert(ZadReszta.class, getIdFactory().generateId(), null, 5, 5);

        tmpl.update("DELETE FROM zadania_id");
        int rows = tmpl.update(TableDefinitionUtils.getPreparedStatementCreator(ZadaniaId.class, id_polozenie, id_reszta));
        assert (rows == 1);
    }
}
